<?php

namespace App\Console\Commands;

use App\Console\Services\NacosSyncService;
use App\Http\Common\nacos\entity\NamespaceServiceEntity;
use App\Http\Common\nacos\NacosFactory;
use App\Http\Common\nacos\service\NamespaceService;
use Illuminate\Console\Command;

class NacosRefreshConfig extends Command
{
    /**
     * The name and signature of the console command.
     * php artisan update-nacos-config
     * @var string
     */
    protected $signature = 'update-nacos-config';

    /**
     * The console command description.
     *
     * @var string
     */
    protected $description = 'check nacos config every minute';

    private $nacosService;

    /**
     * Create a new command instance.
     *
     * @return void
     */
    public function __construct(NacosSyncService $service)
    {
        parent::__construct();
        $this->nacosService = $service;
    }

    /**
     * Execute the console command.
     *
     * @return int
     */
    public function handle()
    {
        $service = new NamespaceService();
        $tenant = 'tenant';
        $namespace = $service->setTenant($tenant)->get();
        if (!$namespace) {
            NacosFactory::setConfig(NamespaceService::class, [
                'customNamespaceId' => $tenant,
                'namespaceName' => $tenant,
                'namespaceDesc' => $tenant,
            ]);
        }
        echo '租户id:' . $namespace;
    }
}
